package com.gongjian.utile;

import javax.net.ssl.HttpsURLConnection;
import javax.swing.plaf.PanelUI;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
 * @author 董浩
 * @Description
 * @create 2019-03-20 17:24
 */
public class Https {

    public static String https(String url) throws IOException {
        //创建URL对象
        URL reqURL = new URL(url);
        HttpsURLConnection httpsConn = (HttpsURLConnection) reqURL.openConnection();
        InputStream inputStream=httpsConn.getInputStream();
        //读取服务器的响应内容并显示
        int len;
        byte[] bytes=new byte[8912];
        String re="";
        while ((len=inputStream.read(bytes,0,bytes.length))!=-1) {
            re+=new String(bytes,0,len);
        }
        return  re;
    }

    public  static String wxLoginApi(String js_code) throws IOException {
       String appid="wxe3d5066910d65cb5";
       String secret="b1f7cc0fa98eeccd4a4793d919629a81";
        return https("https://api.weixin.qq.com/sns/jscode2session?appid="+appid+"&secret="+secret+"&js_code="+js_code+"&grant_type=authorization_code");
    }
}
